<template>
  <h2>姓名：{{ person.name }}</h2>
  <h2>年龄：{{ person.age }}</h2>
  <h2>工资：{{ person.job.j1.salary }}</h2>
  <button @click="person.name += '~'">改姓名</button>
  <button @click="person.age++">改年龄</button>
  <button @click="person.job.j1.salary++">涨工资</button>
</template>
  
  <script>
import { reactive, computed, ref, watch } from "vue";
export default {
  name: "App",
  components: {},

  setup(props, context) {
    let person = reactive({
      name: "张三",
      age: 18,
      job: {
        j1: {
          salary: 20,
        },
      },
    });

    // reactive响应式数据  无法正确获取新旧值
    // 强制开启深度监视
    // watch(
    //   person,
    //   (newValue, oldValue) => {
    //     console.log(newValue, oldValue);
    //   },
    //   {
    //     immediate: true,
    //     deep: true,
    //   }
    // );
    // reactive响应式数据监视某个属性
    watch(
    ()=>person.name,
      (newValue, oldValue) => {
        console.log(newValue, oldValue);
      },
      {
        immediate: true,
       deep:true
      }
    );
    // reactive响应式数据监视某些属性
  //   watch(
  //  [ ()=>person.name, ()=>person.age],
  //     (newValue, oldValue) => {
  //       console.log(newValue, oldValue);
  //     },
  //     {
  //       immediate: true,
  //      deep:true
  //     }
  //   ); 
// reactive  对象   deep:true
  watch(
    ()=>person.job,
      (newValue, oldValue) => {
        console.log(newValue, oldValue);
      },
      {
        immediate: true,
        deep:true
      }
    );

    return { person };
  },
};
</script>
  
  <style>
</style>
  